﻿using Conqueror.Storage;
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Conqueror.WP.Storage
{
    public class ApplicationDataContext : DataContext
    {
        // Specify the connection string as a static, used in main page and app.xaml.
        public static string DBConnectionString = "Data Source=isostore:/Database.sdf";

        // Pass the connection string to the base class.
        public ApplicationDataContext(string connectionString) : base(connectionString) { }

        public Table<IUser> Users { get; set; }
        public Table<IScore> Scores { get; set; }
        public Table<IQuickAction> QuickActions { get; set; }
        public Table<IMap> Maps { get; set; }
        public Table<IFrenemy> Frenemies { get; set; }
        public Table<ICachedImage> CachedImages { get; set; }

        public static ApplicationDataContext InitializeDatabase()
        {
            // Create the database if it does not yet exist.
            using (ApplicationDataContext db = new ApplicationDataContext("isostore:/Database.sdf"))
            {
                if (!db.DatabaseExists())
                {
                    // Create the database.
                    db.CreateDatabase();
                }
                return db;
            }
        }
    }
}
